home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.4 KB | 451 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTime.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #if !defined(FWTIME_H) && !defined(__ODFRC__)
- #define FWTIME_H
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TIME_H__)
- #include <Time.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__OSUTILS__)
- #include <OSUtils.h>
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(__TIME_H__)
- #include <Time.h>
- #endif
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
- class FW_CTimeSpan;
- class FW_CString;
-
- //========================================================================================
- // FW_CTime
- //========================================================================================
-
- class FW_CTime
- {
- public:
- enum DateForm { kShortDate, kLongDate, kAbbreviatedDate};
-
- FW_CTime();
- FW_CTime(time_t theTime);
- FW_CTime(const FW_CTime& other);
- FW_CTime(short year, short month, short day, short hour, short minute, short second);
- ~FW_CTime();
-
- static FW_CTime GetCurrentTime(); // Create a new time initialized to the current time
-
- // Accessors
- time_t GetTime() const;
-
- short GetSecond() const;
- short GetMinute() const;
- short GetHour() const;
- short GetDayOfWeek() const;
- short GetDayOfMonth() const;
- short GetDayOfYear() const;
- short GetMonth() const;
- short GetYear() const;
- short IsDaylightSavings() const;
-
- #ifdef FW_BUILD_MAC
- static unsigned long MacConvertODTimeToMacTime(ODTime t);
- static ODTime MacConvertMacTimeToODTime(unsigned long t);
- #endif
-
- void GetTimeString(FW_CString& timeString, FW_Boolean displaySeconds) const;
- void GetDateString(FW_CString& dateString, DateForm form) const;
-
- const FW_CTime& operator=(const FW_CTime& other);
- const FW_CTime& operator=(time_t time);
-
- FW_CTime operator-(FW_CTimeSpan timeSpan) const;
- FW_CTimeSpan operator-(FW_CTime time) const;
- FW_CTime operator+(FW_CTimeSpan timeSpan) const;
- const FW_CTime& operator-=(FW_CTimeSpan timeSpan);
- const FW_CTime& operator+=(FW_CTimeSpan timeSpan);
-
- FW_Boolean operator==(FW_CTime time) const;
- FW_Boolean operator!=(FW_CTime time) const;
- FW_Boolean operator<(FW_CTime time) const;
- FW_Boolean operator>(FW_CTime time) const;
- FW_Boolean operator<=(FW_CTime time) const;
- FW_Boolean operator>=(FW_CTime time) const;
-
- private:
- time_t fTime;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CTime constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTime::FW_CTime(time_t theTime) :
- fTime(theTime)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTime::FW_CTime(const FW_CTime& other) :
- fTime(other.fTime)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime destructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTime::~FW_CTime()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::GetTime
- //----------------------------------------------------------------------------------------
-
- inline time_t FW_CTime::GetTime() const
- {
- return fTime;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator =
- //----------------------------------------------------------------------------------------
-
- inline const FW_CTime& FW_CTime::operator=(const FW_CTime& other)
- {
- fTime = other.GetTime();
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator =
- //----------------------------------------------------------------------------------------
-
- inline const FW_CTime& FW_CTime::operator=(time_t time)
- {
- fTime = time;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator ==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator==(FW_CTime time) const
- {
- return fTime == time.GetTime();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator !=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator!=(FW_CTime time) const
- {
- return fTime != time.GetTime();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator <
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator<(FW_CTime time) const
- {
- return fTime < time.GetTime();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator >
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator>(FW_CTime time) const
- {
- return fTime > time.GetTime();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator <=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator<=(FW_CTime time) const
- {
- return fTime <= time.GetTime();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTime::operator >=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTime::operator>=(FW_CTime time) const
- {
- return fTime >= time.GetTime();
- }
-
-
- class FW_CTimeSpan
- {
- public:
- FW_CTimeSpan();
- FW_CTimeSpan(time_t theTimeSpan);
- FW_CTimeSpan(const FW_CTimeSpan& other);
- FW_CTimeSpan(long days, short hours, short minutes, short seconds);
- ~FW_CTimeSpan();
-
- short GetSeconds() const;
- short GetMinutes() const;
- short GetHours() const;
- long GetDays() const;
-
- long GetTotalSeconds() const;
- long GetTotalMinutes() const;
- long GetTotalHours() const;
-
- const FW_CTimeSpan& operator=(const FW_CTimeSpan& source);
- const FW_CTimeSpan& operator-=(FW_CTimeSpan timeSpan);
- const FW_CTimeSpan& operator+=(FW_CTimeSpan timeSpan);
-
- FW_CTimeSpan operator-(FW_CTimeSpan timeSpan) const;
- FW_CTimeSpan operator+(FW_CTimeSpan timeSpan) const;
-
- FW_Boolean operator==(FW_CTimeSpan timeSpan) const;
- FW_Boolean operator!=(FW_CTimeSpan timeSpan) const;
- FW_Boolean operator<(FW_CTimeSpan timeSpan) const;
- FW_Boolean operator>(FW_CTimeSpan timeSpan) const;
- FW_Boolean operator<=(FW_CTimeSpan timeSpan) const;
- FW_Boolean operator>=(FW_CTimeSpan timeSpan) const;
-
- private:
- long fTotalSeconds;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan::FW_CTimeSpan()
- {
- fTotalSeconds = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan::FW_CTimeSpan(time_t theTimeSpan)
- {
- fTotalSeconds = theTimeSpan;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan::FW_CTimeSpan(const FW_CTimeSpan& other)
- {
- fTotalSeconds = other.fTotalSeconds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan constructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan::FW_CTimeSpan(long days, short hours, short minutes, short seconds)
- {
- // fTotalSeconds = (days * 86400L) + (hours * 3600) + (minutes * 60) + seconds;
- fTotalSeconds = seconds + 60L*(minutes + 60L*(hours + 24*days));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan destructor
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan::~FW_CTimeSpan()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetSeconds
- //----------------------------------------------------------------------------------------
-
- inline short FW_CTimeSpan::GetSeconds() const
- {
- return fTotalSeconds % 60;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetMinutes
- //----------------------------------------------------------------------------------------
-
- inline short FW_CTimeSpan::GetMinutes() const
- {
- return (fTotalSeconds % 3600) / 60;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetHours
- //----------------------------------------------------------------------------------------
-
- inline short FW_CTimeSpan::GetHours() const
- {
- return (fTotalSeconds % 86400L) / 3600;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetDays
- //----------------------------------------------------------------------------------------
-
- inline long FW_CTimeSpan::GetDays() const
- {
- return fTotalSeconds / 86400L; // 60 seconds * 60 minutes * 24 hours
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetTotalSeconds
- //----------------------------------------------------------------------------------------
-
- inline long FW_CTimeSpan::GetTotalSeconds() const
- {
- return fTotalSeconds;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetTotalMinutes
- //----------------------------------------------------------------------------------------
-
- inline long FW_CTimeSpan::GetTotalMinutes() const
- {
- return fTotalSeconds / 60;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::GetTotalHours
- //----------------------------------------------------------------------------------------
-
- inline long FW_CTimeSpan::GetTotalHours() const
- {
- return fTotalSeconds / 3600;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator =
- //----------------------------------------------------------------------------------------
-
- inline const FW_CTimeSpan& FW_CTimeSpan::operator=(const FW_CTimeSpan& source)
- {
- fTotalSeconds = source.GetTotalSeconds();
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator -=
- //----------------------------------------------------------------------------------------
-
- inline const FW_CTimeSpan& FW_CTimeSpan::operator-=(FW_CTimeSpan source)
- {
- fTotalSeconds -= source.GetTotalSeconds();
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator +=
- //----------------------------------------------------------------------------------------
-
- inline const FW_CTimeSpan& FW_CTimeSpan::operator+=(FW_CTimeSpan source)
- {
- fTotalSeconds += source.GetTotalSeconds();
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator -
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan FW_CTimeSpan::operator-(FW_CTimeSpan timeSpan) const
- {
- return FW_CTimeSpan((time_t)(GetTotalSeconds() - timeSpan.GetTotalSeconds()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator +
- //----------------------------------------------------------------------------------------
-
- inline FW_CTimeSpan FW_CTimeSpan::operator+(FW_CTimeSpan timeSpan) const
- {
- return FW_CTimeSpan((time_t)(GetTotalSeconds() + timeSpan.GetTotalSeconds()));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator ==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator==(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds == timeSpan.GetTotalSeconds();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator !=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator!=(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds != timeSpan.GetTotalSeconds();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator <
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator<(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds < timeSpan.GetTotalSeconds();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator >
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator>(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds > timeSpan.GetTotalSeconds();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator <=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator<=(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds <= timeSpan.GetTotalSeconds();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTimeSpan::operator >=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CTimeSpan::operator>=(FW_CTimeSpan timeSpan) const
- {
- return fTotalSeconds >= timeSpan.GetTotalSeconds();
- }
-
- #endif
-